home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / Perspective Bitmap ƒ / perspective sample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  5.0 KB  |  161 lines  |  [TEXT/KAHL]

  1. /*
  2.     perspective bitmap sample code
  3.  
  4.     We will retreive a bitmap from the resource fork of this application. We will convert this bitmap into a bitmap
  5.     shape. This shape will be drawn "normally" and it will be drawn perspected. We collect all of the images into one
  6.     picture. The viewPort attached to the window will be set to a dither level of 4. This will make the drawing to a 
  7.     "gray" monitor look cool.
  8.     
  9.     NOTES:
  10.     • This file requires the following files to run correctly:
  11.         "graphics shell.c", "color library.c", "graphics debug library.c", "mapping library.c", "picture library.c", 
  12.         "qd library.c", "shape library.c", "transform library.c".
  13.         
  14.     • This file prints the "best" in landscape mode.
  15.  
  16.     ©1990 - 1994 Apple Computer, Inc.
  17.     All rights reserved.
  18. */
  19.  
  20. #include <Events.h>
  21. #include <Windows.h>
  22.  
  23. #include "graphics toolbox.h"
  24. #include "graphics libraries.h"
  25. #include "graphics debugging.h"
  26. #include "qd library.h"
  27. #include "graphics shell.h"
  28.  
  29. //
  30. //  Set up the title and size of the window 
  31. //
  32. Rect     gWindowQDRect = {40, 60, 250, 480};
  33. Str255     gWindowTitle = "\pPerspective Sample";
  34.  
  35. //
  36. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  37. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  38. //    With  gGraphicsHeapSize set to 65k, I had 5 free blocks left in the graphics gxHeap. Sounds good to me.
  39. //
  40. //    If we were not dithering the viewPort attached to the window, we would need about 30k for the graphics gxHeap.
  41. //
  42. long        gGraphicsHeapSize = 65;
  43.  
  44. //
  45. //    These gxPolygon structures are used to generate a perspective gxMapping: 
  46. //
  47. long polyA[] = {4, ff(0), ff(0), ff(100), ff(0), ff(100), ff(100), ff(0), ff(100)};    //  100x100 upright
  48. long polyB[] = {4, ff(20), ff(20), ff(60), ff(-20), ff(110), ff(95), ff(5), ff(105)};    //  offset & distorted 
  49.  
  50. gxShape     updateShape;
  51.  
  52.  
  53.  
  54. /*------ CreateImage -----------------------------------------------------------------------------------*/
  55.  
  56. gxShape CreateImage(void);
  57. gxShape CreateImage()
  58. {
  59.     gxShape         bitsShape, shadowShape, image;
  60.     gxTransform     perspector;
  61.     gxRectangle     bounds;
  62.     gxMapping         polyMap;
  63.  
  64.     GXIgnoreGraphicsNotice (transform_already_set);
  65.  
  66.     image = GXNewShape(gxPictureType);
  67.  
  68.     //
  69.     //  Get the bitsShape from the resource file.  If we do not get it, GXValidateShape will drop us into the debugger.
  70.     //
  71.     bitsShape = GetPixMapShape(128);
  72.     GXValidateShape (bitsShape);
  73.  
  74.     GXGetShapeBounds(bitsShape, 0L, &bounds);
  75.     shadowShape = GXNewRectangle(&bounds);
  76.     GXMoveShape(shadowShape, ff(5), ff(5));
  77.     GXSetShapeTransform(shadowShape, GXGetShapeTransform(bitsShape));  
  78.  
  79.     AddToShape(image, shadowShape);
  80.     AddToShape(image, bitsShape);
  81.  
  82.     PolyToPolyMap((gxPolygon *) &polyA, (gxPolygon *) &polyB, &polyMap);
  83.     RotateMapping(&polyMap, ff(23), 0, 0);
  84.  
  85.     perspector = GXNewTransform();
  86.     GXSetTransformMapping(perspector, &polyMap);
  87.     GXMoveTransform(perspector, ff(265), ff(5));
  88.  
  89.     AddToPicture(image, shadowShape, nil, nil, perspector);
  90.     AddToPicture(image, bitsShape, nil, nil, perspector);
  91.  
  92.     GXDisposeShape(shadowShape);
  93.     GXDisposeShape(bitsShape);
  94.     GXDisposeTransform(perspector); 
  95.  
  96.     GXPopGraphicsNotice ();
  97.     
  98.     return image;
  99. }
  100.  
  101.  
  102. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  103.  
  104. void DoInitialization(theWindow)
  105. WindowPtr theWindow;
  106. {
  107.     gxViewPort        windowViewPortParent;
  108.  
  109.     //
  110.     //    Get the viewPort that is attached to the window, and set the dither of this viewPort to 4.  Which
  111.     //    will mean that all objects that are drawn into window will be dithered at a dither level of 4.
  112.     //
  113.      windowViewPortParent = GXGetWindowViewPort(theWindow);
  114.     GXSetViewPortDither(windowViewPortParent, 4);
  115.  
  116.     updateShape = CreateImage();
  117. }
  118.  
  119.  
  120. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  121.  
  122. void DoDraw(theWindow)
  123. WindowPtr theWindow;
  124. {
  125.     GXDrawShape(updateShape);
  126. }
  127.  
  128.  
  129. /*------ DoDispose -------------------------------------------------------------------------------------*/
  130.  
  131. void DoDispose(theWindow)
  132. WindowPtr theWindow;
  133. {
  134.     //  
  135.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  136.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  137.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  138.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  139.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  140.     //
  141.     GXDisposeShape(updateShape);
  142.     GXDisposeShape(gWindowBoundsShape);
  143.        DisposeWindow(theWindow);
  144. }
  145.  
  146.  
  147. /*------ DoClick ---------------------------------------------------------------------------------------*/
  148.  
  149. void DoClick( orgMouseLoc, theWindow )
  150. gxPoint        orgMouseLoc;
  151. WindowPtr     theWindow;
  152. {
  153. }
  154.  
  155.  
  156. /*------ DoIdle -----------------------------------------------------------------------------------------*/
  157.  
  158. void DoIdle(theWindow)
  159. WindowPtr theWindow;
  160. {
  161. }